//
//  CNewOrderFaultyPartsVC.m
//  ProjectforHDX
//
//  Created by motom on 16/8/12.
//  Copyright © 2016年 H.DX. All rights reserved.
//

#import "CNewOrderFaultyPartsVC.h"
#import "FailurePartsModel.h"
#import "CNewOrderPartsCell.h"

#import "MHScanViewController.h"

@interface CNewOrderFaultyPartsVC ()<UITableViewDataSource,UITableViewDelegate,UISearchBarDelegate>

@property (nonatomic, strong) UITableView *tableView;

@property(nonatomic,weak)UISearchBar *searchBar;

@property(nonatomic, strong)NSString *searchKey;

@property(nonatomic ,strong)NSMutableArray *faultedPlates;

@property(nonatomic, strong)NSDictionary *altogetherDic;

@property (nonatomic, strong) UIImageView *nodataImage;

@end

@implementation CNewOrderFaultyPartsVC


-(NSMutableArray *)faultedPlates
{
    if (!_faultedPlates) {
        _faultedPlates = [NSMutableArray array];
    }
    return _faultedPlates;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupView];
    if (self.judge == PartDefault) {
        [self requestDefaultData:@""];
    }
    else if(self.judge == PartOneline)
    {
        [self requestOneLineData:@""];
    }
}

- (void)setupData
{
    FailurePartsModel *model = [[FailurePartsModel alloc]init];
    model.faultid = @"ddssdfs";
    model.name = @"dfadfasf";
    model.code = @"rerewr";
    model.sn = @"rwrwerew";
    model.version = @"sdfdsf";
    model.rating = @"4";
    [self.faultedPlates addObject:model];
    
    FailurePartsModel *model2 = [[FailurePartsModel alloc]init];
    model2.faultid = @"ddssdfs";
    model2.name = @"dfadfasf";
    model2.code = @"rerewr";
    model2.sn = @"rwrwerew";
    model2.version = @"sdfdsf";
    model2.rating = @"4";
    [self.faultedPlates addObject:model2];
    
    [self.tableView reloadData];
}


#pragma -mark 搜索故障件
-(void)requestDefaultData:(NSString *)searchKey
{
    self.nodataImage.hidden = YES;
    [[BDHUD sharedManager] showBDHUD:self.view title:@"HUD.title"];
    sleep(0.5);
    [[BDHUD sharedManager] dismissHUD];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"searchKey"] = searchKey;
    if (self.customerID) {
        params[@"customerID"] = self.customerID;
    }
    if (self.fualtPartType){
        params[@"faultPartType"] = self.fualtPartType;
    }
    params[@"orderType"] = self.orderType;

    NSLog(@"－－－－－－－%@",params);
    
    [AFHttpTool postJsonDatawithUrl:@"/getFailureparts" parameters:[params mutableCopy] success:^(id responseObject) {
        
        
        if(1==[[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue]){
            if([[responseObject objectForKey:@"data"] isKindOfClass:[NSArray class]]){
             NSMutableArray *data=[responseObject objectForKey:@"data"] ;
    
             NSMutableArray *faultParts = [FailurePartsModel failurePartsWithArray:data];
                
                if (faultParts.count == 0) {
                    self.nodataImage.hidden = NO;

                }
            
//                if (faultParts.count > 20) {
//                    self.faultedPlates = [faultParts subarrayWithRange:NSMakeRange(0, 20)];
//                }
//                else
//                {
                    self.faultedPlates = faultParts;
//                }

                [self.tableView reloadData];
            }
            else{
                //返回数据出问题 弹出服务器返回信息
                if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                    [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
                }
                else{
                    [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.nothing"]];
                }
            }
        }
        else{
            //返回数据出问题 弹出服务器返回信息
            if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            }
            else{
                [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.nothing"]];
            }
            
        }
       
    } fail:^(id responseObject, NSError *error) {
//        [[BDHUD sharedManager] dismissHUD];
//        [[BDHUD sharedManager] showWords:[error.userInfo objectForKey:@"NSLocalizedDescription"]];
        if (!self.faultedPlates.count) {
            
            UIImageView *nodataImage = [[UIImageView alloc]init];
            //        nodataImage.center = self.tabelView.center;
            nodataImage.image = BDFILEIMAGENAEM(@"default/none.png");
            [nodataImage setSize:CGSizeMake(200, 200)];
            nodataImage.top = 150;
            nodataImage.left = [UIScreen mainScreen].bounds.size.width * 0.5 - nodataImage.bounds.size.width * 0.5;
            [self.view addSubview:nodataImage];
            
        }

    }];
}

#pragma -mark 搜索一线备件
-(void)requestOneLineData:(NSString *)searchKey
{
    self.nodataImage.hidden = YES;
    [[BDHUD sharedManager] showBDHUD:self.view title:@"HUD.title"];
    sleep(0.5);
    [[BDHUD sharedManager] dismissHUD];
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"searchKey"] = searchKey;
    params[@"customerID"] = self.customerID;
    params[@"plateCode"]=self.code;
    params[@"number"]=@"1";
    params[@"existOneLineIDs"]=self.existOneLineIDs;
    
    NSLog(@"------%@",params);
    
    [AFHttpTool postJsonDatawithUrl:@"/getOneLineParts" parameters:[params mutableCopy] success:^(id responseObject) {
        
        NSLog(@"======%@",responseObject);
        
        
        if(1==[[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue]){
            if([[responseObject objectForKey:@"data"] isKindOfClass:[NSArray class]]){
                
                               NSArray *data=[responseObject objectForKey:@"data"] ;
//                NSArray *arr = @[@{
//                                     @"id":@"1235",
//                                     @"name":@"主板",
//                                     @"code":@"XX255",
//                                     @"version":@"v1.0",
//                                     @"sn":@"L123456",
//
//                                     },@{
//                                     @"id":@"1235",
//                                     @"name":@"主板",
//                                     @"code":@"XX255",
//                                     @"version":@"v1.0",
//                                     @"sn":@"L123456",
//                                     
//                                     }];
                
                                      
                self.faultedPlates = [FailurePartsModel failurePartsWithArray:data];
                if (self.faultedPlates.count == 0) {
                    self.nodataImage.hidden =NO;
                  
//                    UILabel *nodataTitle = [[UILabel alloc]init];
//                    nodataTitle.text = [UtilCheck language:@"message.nodata"];
//                    [nodataTitle sizeToFit];
//                    nodataTitle.top = nodataImage.bottom +5;
//                    nodataTitle.left = nodataImage.left + nodataImage.bounds.size.width * 0.5 - nodataTitle.bounds.size.width * 0.5;
//                    [self.view addSubview:nodataTitle];

                }
                [self.tableView reloadData];
            }
            else{
                //返回数据出问题 弹出服务器返回信息
                if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                    [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
                }
                else{
                    [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.nothing"]];
                }
            }
        }
        else{
            //返回数据出问题 弹出服务器返回信息
            if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            }
            else{
                [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.nothing"]];
            }
            
        }
    } fail:^(id responseObject, NSError *error) {
//        [[BDHUD sharedManager] dismissHUD];
//        [[BDHUD sharedManager] showWords:[error.userInfo objectForKey:@"NSLocalizedDescription"]];
        if (!self.faultedPlates.count) {
            UIImageView *nodataImage = [[UIImageView alloc]init];
            //        nodataImage.center = self.tabelView.center;
            nodataImage.image = BDFILEIMAGENAEM(@"default/img_noData");
            [nodataImage sizeToFit];
            nodataImage.top = 150;
            nodataImage.left = [UIScreen mainScreen].bounds.size.width * 0.5 - nodataImage.bounds.size.width * 0.5;
            [self.view addSubview:nodataImage];
            
            UILabel *nodataTitle = [[UILabel alloc]init];
            nodataTitle.text = [UtilCheck language:@"message.nodata"];
            [nodataTitle sizeToFit];
            nodataTitle.top = nodataImage.bottom +5;
            nodataTitle.left = nodataImage.left + nodataImage.bounds.size.width * 0.5 - nodataTitle.bounds.size.width * 0.5;
            [self.view addSubview:nodataTitle];
        }

    }];
    
    }

#pragma -mark 初始化页面
//初始化view  the very essence for romance is uncertainty
-(void)setupView
{
    self.labnav.textColor = [UIColor whiteColor];
    if (self.judge == PartDefault) {
        self.labnav.text = [UtilCheck language:@"customer.chooseFaultPlate"];
    }
    if (self.judge == PartOneline) {
        self.labnav.text = [UtilCheck language:@"customer.chooseOneline"];
    }
    
    UITableView *table =[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStyleGrouped];
    table.delegate = self;
    table.dataSource = self;
    table.separatorStyle = UITableViewCellSeparatorStyleNone;
    [table setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-40)];
    self.tableView.backgroundColor = [UtilCheck hexStringToColor:@"F7F5FA" alpha:1.0];
    [self.view addSubview:table];
    self.tableView = table;
    self.tableView.bounces = NO;
    
    UISearchBar *search = [[UISearchBar alloc]init];
    if (self.judge == PartOneline) {
        [search setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
    }
    else
    {
        [search setFrame:CGRectMake(40, 0, SCREEN_WIDTH-40, 40)];
    }
    search.backgroundColor =[UIColor whiteColor];
    [search setImage:BDFILEIMAGENAEM(@"default/iconfont-sousuo") forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
    if (self.judge == PartDefault) {
        //扫一扫按钮
        UIButton *btn = [[UIButton alloc]init];
        [btn setImage:BDFILEIMAGENAEM(@"Order/scan") forState:UIControlStateNormal];
        [btn setBackgroundColor:[UtilCheck hexStringToColor:@"e8e8e8" alpha:1.0]];
        [btn setFrame:CGRectMake(0, 0, 40, 40)];
        btn.imageEdgeInsets = UIEdgeInsetsMake(5, 10, 10, 10);
        [btn addTarget:self action:@selector(openScanView) forControlEvents:UIControlEventTouchUpInside];
        
        [self.view addSubview:btn];

        
        
        UILabel *title = [[UILabel alloc]init];
        title.textColor = [UtilCheck hexStringToColor:@"235DC1" alpha:1.0];
        title.text = [UtilCheck language:@"title.SYS"];
        title.font = CustomFont(8);
        title.adjustsFontSizeToFitWidth = YES;
        [title setFrame:CGRectMake(8, 30, 40, 10)];
        [btn addSubview:title];
        
        
        search.placeholder = [UtilCheck language:@"order.faultpart.codePlaceholder"];
        
        UIImageView *nodataImage = [[UIImageView alloc]init];
        //        nodataImage.center = self.tabelView.center;
        nodataImage.image = BDFILEIMAGENAEM(@"default/none.png");
        [nodataImage setSize:CGSizeMake(100, 130)];
        nodataImage.top = 150;
        nodataImage.left = [UIScreen mainScreen].bounds.size.width * 0.5 - nodataImage.bounds.size.width * 0.5;
        self.nodataImage= nodataImage;
        self.nodataImage.hidden = YES;
        [self.view addSubview:nodataImage];
        

    }
    if (self.judge == PartOneline) {
        search.placeholder = [UtilCheck language:@"order.choice.or.input.good"];

    }
    UITextField *searchField = [search valueForKey:@"_searchField"];
    self.searchBar = search;

    [searchField setValue:[UtilCheck hexStringToColor:@"ababab" alpha:1.0] forKeyPath:@"_placeholderLabel.textColor"];
    searchField.font = CustomFont(13);
    
    self.tableView.tableHeaderView = [[UIView alloc]init];
    [self.view addSubview:search];
    search.backgroundImage = [self imageWithColor:[UtilCheck hexStringToColor:@"#E8E8E8" alpha:1.0] size:search.bounds.size];
 
    search.delegate = self;

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark 扫描界面
- (void)openScanView
{
    MHScanViewController *scanVC = [[MHScanViewController alloc] init];
    scanVC.isdismiss = YES;
    scanVC.rebackData = ^(NSString *retStr) {
        NSLog(@"回传过来的的扫面结果%@", retStr);
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        
        params[@"code"] = retStr;
        
        if (self.customerID) {
            params[@"customerID"] = self.customerID;
        }
        
        params[@"orderType"] = self.orderType;
        [[BDHUD sharedManager] showBDHUD:self.view title:nil];
        [AFHttpTool postJsonDatawithUrl:@"/scanAddFailureparts" parameters:params success:^(id responseObject) {
            [[BDHUD sharedManager] dismissHUD];
            NSArray *arr = responseObject[@"data"];
            if (arr.count != 0) {
                NSDictionary *dic = arr[0];
                
                NSLog(@"_++++++++++++++1%@",dic);
                
                if (self.selectedIndex == 0) {
                    
                    if (_judge == 0) {
                        
                        if (arr.count == 1) {
                            NSDictionary *dataDic = [[NSDictionary alloc]initWithObjectsAndKeys:dic[@"version"],@"versionCode",dic[@"faultid"],@"faultid",dic[@"name"],@"name",dic[@"code"],@"code",self.tag,@"tag",dic[@"sn"],@"sn", nil];
                            _altogetherDic = [[NSDictionary alloc]initWithDictionary:dataDic];
                            NSLog(@"_++++++++++++++2%@",_altogetherDic);

                        }else {
                            NSDictionary *dataDic = [[NSDictionary alloc]initWithObjectsAndKeys:@"",@"versionCode",dic[@"faultid"],@"faultid",dic[@"name"],@"name",dic[@"code"],@"code",self.tag,@"tag",dic[@"sn"],@"sn", nil];
                            _altogetherDic = [[NSDictionary alloc]initWithDictionary:dataDic];
                        }
                       
                        
                    }else if (_judge == 1){
                        NSDictionary *dataDic = [[NSDictionary alloc]initWithObjectsAndKeys:dic[@"faultPartType"],@"faultPartType",dic[@"version"],@"version",dic[@"id"],@"faultid",dic[@"name"],@"name",dic[@"code"],@"code",self.tag,@"tag",dic[@"sn"],@"sn", nil];
                        NSLog(@"_++++++++++++++%@",dataDic);

                        _altogetherDic = [[NSDictionary alloc]initWithDictionary:dataDic];
                        
                    }
                    
                    //创建一个消息对象
                    NSNotification * notice = [NSNotification notificationWithName:@"fault" object:nil userInfo:_altogetherDic];
                    //发送消息
                    [[NSNotificationCenter defaultCenter]postNotification:notice];
                    
                    [[self navigationController] popViewControllerAnimated:YES];
                }else if (self.selectedIndex == 1){
                    
                    if (arr.count == 1) {
                        NSMutableDictionary *dataDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:dic[@"version"],@"version",dic[@"id"],@"faultid",dic[@"name"],@"name",dic[@"code"],@"code",self.tag,@"tag",dic[@"version"],@"version", nil];
                        
                        //创建一个消息对象
                        NSNotification * notice = [NSNotification notificationWithName:@"replace" object:nil userInfo:dataDic];
                        //发送消息
                        [[NSNotificationCenter defaultCenter]postNotification:notice];
                        [[self navigationController] popViewControllerAnimated:YES];
                    }else {
                        NSMutableDictionary *dataDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:dic[@"version"],@"version",dic[@"id"],@"faultid",dic[@"name"],@"name",dic[@"code"],@"code",self.tag,@"tag",@"",@"version", nil];
                        
                        //创建一个消息对象
                        NSNotification * notice = [NSNotification notificationWithName:@"replace" object:nil userInfo:dataDic];
                        //发送消息
                        [[NSNotificationCenter defaultCenter]postNotification:notice];
                        [[self navigationController] popViewControllerAnimated:YES];
                    }
                }

                
//                //创建一个消息对象
//                NSNotification * notice = [NSNotification notificationWithName:@"fault" object:nil userInfo:dic];
//                //发送消息
//                [[NSNotificationCenter defaultCenter]postNotification:notice];
//
            }else {
                [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.did.not.find.the.related.plate"]];
            }

        } fail:^(id responseObject, NSError *error) {
            [[BDHUD sharedManager] dismissHUD];
            [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.title.the.data.load.failure"]];
        }];
    };
    CustomNavigationController *vc = [[CustomNavigationController alloc ]initWithRootViewController:scanVC];
    
    [self presentViewController:vc animated:YES completion:nil];

}


//取消searchbar背景色
- (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size
{
    CGRect rect = CGRectMake(0, 0, size.width, size.height);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}


#pragma -mark tableview 的 delegate  datasource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
        return self.faultedPlates.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CNewOrderPartsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[CNewOrderPartsCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    FailurePartsModel *model;
    model = self.faultedPlates[indexPath.row];
        
    if (self.judge == PartDefault) {
        cell.isDefaultPart = YES;
    }
    cell.index = self.selectedIndex;
    [cell setDefaultPart:model];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

#pragma -mark 发送通知
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.selectedIndex == 0) {
        FailurePartsModel *model = self.faultedPlates[indexPath.row];
        
        if (_judge == 0) {
            NSDictionary *dataDic = [[NSDictionary alloc]initWithObjectsAndKeys:model.version,@"version",model.faultid,@"faultid",model.name,@"name",model.code,@"code",self.tag,@"tag",model.sn,@"sn",model.is_version,@"isVersion", nil];
            _altogetherDic = [[NSDictionary alloc]initWithDictionary:dataDic];
            
        }else if (_judge == 1){
           // NSDictionary *dataDic = [[NSDictionary alloc] initWithObjectsAndKeys:model.faultPartType,@"faultPartType",model.version,@"version",model.faultid,@"faultid",model.name,@"name",model.code,@"code",self.tag,@"tag",model.sn,@"sn",model.is_version,@"isVersion", nil];
            
            NSMutableDictionary *dataDic = [NSMutableDictionary dictionaryWithCapacity:0];
            if (![Toolobject IsEmptyString:model.faultPartType]) {
                [dataDic setObject:model.faultPartType forKey:@"faultPartType"];
            }
            
            [dataDic setObject:model.version forKey:@"version"];
            [dataDic setObject:model.faultid forKey:@"faultid"];
            [dataDic setObject:model.name forKey:@"name"];
            [dataDic setObject:model.code forKey:@"code"];
            [dataDic setObject:self.tag forKey:@"tag"];
//            [dataDic setObject:model.sn forKey:@"sn"];
            [dataDic setObject:model.is_version forKey:@"is_version"];
            
            _altogetherDic = [[NSDictionary alloc]initWithDictionary:dataDic];
            
            

        }
        
        //创建一个消息对象
        NSNotification * notice = [NSNotification notificationWithName:@"fault" object:nil userInfo:_altogetherDic];
        //发送消息
        [[NSNotificationCenter defaultCenter]postNotification:notice];
        
        [[self navigationController] popViewControllerAnimated:YES];
    }else if (self.selectedIndex == 1){
        FailurePartsModel *model = self.faultedPlates[indexPath.row];
        
        NSMutableDictionary *dataDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:model.version,@"version",model.faultid,@"faultid",model.name,@"name",model.code,@"code",self.tag,@"tag",model.sn,@"sn",model.is_version,@"is_version", nil];
        
        NSLog(@"----%@",dataDic);
        
        //创建一个消息对象
        NSNotification * notice = [NSNotification notificationWithName:@"replace" object:nil userInfo:dataDic];
        //发送消息
        [[NSNotificationCenter defaultCenter]postNotification:notice];
        [[self navigationController] popViewControllerAnimated:YES];
    }
}
#pragma -mark searchbar  的 delegate

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    if ([searchBar.text isEqualToString:@""]) {
        if (self.judge == PartDefault) {
            [self requestDefaultData:@""];
        }
        [[BDHUD sharedManager]showBDHUD:self.view title:[UtilCheck language:@"orderlist.input.name.code.sn"]];
    }
    self.searchKey = searchBar.text;
    if (self.judge == PartOneline) {
        [self requestOneLineData:self.searchKey];
    }
    else if(self.judge == PartDefault)
    {
    [self requestDefaultData:self.searchKey];
    }
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.searchBar resignFirstResponder];
}


-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    if (searchBar.text == nil) {
        [[BDHUD sharedManager]showBDHUD:self.view title:[UtilCheck language:@"orderlist.input.name.code.sn"]];
    }
    self.searchKey = searchBar.text;
    if (self.judge == PartOneline) {
        [self requestOneLineData:self.searchKey];
    }
    else if(self.judge == PartDefault)
    {
        [self requestDefaultData:self.searchKey];
    }
    [searchBar resignFirstResponder];
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    if (self.judge == PartOneline ) {
        return 105;
    }
    if(self.selectedIndex == 0)
    {
        return 85;
    }
    return 85;
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

@end
